/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditorWindow.java
 *
 * Created on Apr 29, 2012, 8:03:19 PM
 */

package org.homullus;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;
import org.lwjgl.opengl.GL11.*;

/**
 *
 * @author Gary
 */
public class EditorWindow extends javax.swing.JPanel
{

    AWTGLCanvas canvas = null;
    public AWTGLCanvas getCanvas() { return canvas; }
    public void setCanvas(AWTGLCanvas c) { canvas = c; }


    /** Creates new form EditorWindow */
    public EditorWindow()
    {
        System.out.println("Creating an EditorWindow");
        setPreferredSize(new Dimension(600,600));
        initComponents();
        try
        {
            canvas = new AWTGLCanvas(){
                @Override
                protected void paintGL() {
                    try
                    {
                        System.out.print("in paintGL");
                        GL11.glViewport(0, 0, canvas.getWidth(), canvas.getHeight());
                        GL11.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
                        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
                        GL11.glMatrixMode(GL11.GL_PROJECTION);
                        GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
                        GL11.glPopMatrix();
                        swapBuffers();
                        repaint();
                    }
                    catch (LWJGLException e)
                    {
                        System.err.print("Error painting GL canvas");
                    }
                }
            };
            add(canvas);
        }
        catch (LWJGLException e)
        {
            System.err.print("Error creating AWTGLCanvas");
        }
    }

    @Override
    public void paint(Graphics g)
    {
        super.paint(g);
        canvas.repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 665, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 515, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
